package com.example.student.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.constants.RdsConstants;
import com.example.common.domain.pojo.Question;
import com.example.common.domain.vo.QuestionVo;
import com.example.common.utils.CacheClient;
import com.example.student.mapper.QuestionMapper;
import com.example.student.service.HomeworkQuestionService;
import com.example.student.service.HomeworkService;
import com.example.student.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> implements QuestionService {

    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private HomeworkService homeworkService;
    @Autowired
    private HomeworkQuestionService homeworkQuestionService;
    @Autowired
    private CacheClient cacheClient;

    @Override
    public QuestionVo getQuestionById(String id) {
        Question question = cacheClient.queryWithLogicalExpire(
                RdsConstants.QUESTION_INFO,
                id,
                Question.class,
                this::getById, // 使用MyBatis-Plus的基础方法
                RdsConstants.CACHE_NULL_TTL,
                TimeUnit.MINUTES,
                false
        );
        QuestionVo questionVo = QuestionVo.from(question);
        return questionVo;
    }

}
